<template>
  <div style="height: 100%">
  <a-card :bordered="false" style="min-height: 800px !important;">
    <a-steps class="steps" :current="currentTab">
      <a-step title="详填表说明" />
      <a-step title="基本信息" />
      <a-step title="专业信息" />
      <a-step title="具体证明材料" />
    </a-steps>
    <div class="content">
      <step1 v-if="currentTab === 0" @nextStep="nextStep" :nowStatus="nowStatus"  />
      <step2 v-if="currentTab === 1" @nextStep="nextStep" @prevStep="prevStep" :tes="professorInfo" :isdisabledF="isdisabledF" @setfiled="setfiled"/>
      <step3 v-if="currentTab === 2" @nextStep="nextStep"  :status="status" :geturl="geturl" @prevStep="prevStep" :tes="professorInfo" :isdisabledF="isdisabledF" @setfiled1="setfiled1" @saveTemp="saveTemp" @ExportPDF="ExportPDF"/>
      <step4 v-if="currentTab === 3" @prevStep="prevStep" :isShow="isShow"  :tes="professorInfo"  @setfiled2="setfiled2" @HandleOk="HandleOk"/>
    </div>
  </a-card>
  </div>
</template>

<script>
  import Step1 from './Step1'
  import Step2 from './Step2'
  import Step3 from './Step3'

  import Step4 from './Step4'
  import {getAction} from '@/api/manage'
  import {postAction} from '@/api/manage';
  import { httpAction } from '@/api/manage'
  export default {
    name: "StepForm",
    components: {
      Step1,
      Step2,
      Step3,
      Step4
    },
    data () {
      return {
        isIosW:false,
        isShow:false,
        isdisabledF:false,
        description: '将一个冗长或用户不熟悉的表单任务分成多个步骤，指导用户完成。',
        currentTab: 0,
        exportPdfUrl:"/org/exportProfessor/exportPDF",
        downloadPdfUrl:"/sys/common/static/",
        url:"/sendToDing",
        nowStatus:0,
        geturl:{
          url:'',
          show:false,
        },
        professorInfo:{
          professorName:'',
          professorSex:'',
          professorBirthday:'',
          professorIdentity:'',
          professorEducationBackground:'',
          professorDegree:'',
          professorAddress:'',
          professorHomeAddress:'',
          professorHealth:'',
          professorOfficeTel:'',
          professorPhone:'',
          professorMajor:'',
          professorSchool:'',
          professorGraduateDate:'',
          professorDeclareCategory:'',
          professorWorkMajor:'',
          professorMajorDate:'',
          professorBeginWork:'',
          professorWorkUnit:'',
          professorPosition:'',
          professorTitle:'',
          professorProjectIntroduce:'',
          professorLeadMsg:'',
          professorApproveMsg:'',
          professorPhotoString:'',
          professorInfoPhotoString:'',
          professorIdString:'',
          professorCommitmentString:'',
          professorResumeString:'',
          professorDegreeImageString:'',
          professorQualificationString:'',
          professorOtherString:'',

        },
        // form
        form: null,
      }
    },
    created(){
        this.selectisdiabaled();
        this.select();
        this.appSource();
    },
    methods: {
      // logOut(){
      //   console.log("logout")
      //   getAction("/sys/logout").then((res) => {
      //     console.log(res)
      //   })
      // },
      appSource() {
        const u = navigator.userAgent, app = navigator.appVersion;
        const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
        if (isiOS) {
          this.isIosW=true;
        }

      },
      selectisdiabaled(){
        getAction("/temporary/diyTemporaryApplicantInfo/selectIsdisabledByuserid").then((res) => {
          this.nowStatus=res.result
          console.log(2222222)
          console.log(this.nowStatus)
          if(res.result==1){
            return this.isdisabledF=true;
          }
        })
      },
      HandleOk(){
          console.log("进入父组件提交");
          const that = this;
          let formType = this.professorInfo.professorDeclareCategory;
          // 访问后台，查找hasChild
          let url = "/sys/category/findById?ids=" + formType;
          getAction(url).then((res) => {
            if (res.success) {
              if (res.result == 0) {
                console.log("进入提交状态");
                let httpurl = this.url;
                let method = '';
                method = 'post';
                console.log("表单提交数据", this.professorInfo);
                httpAction(httpurl, this.professorInfo, method).then((res) => {
                  if (res.success) {
                    that.$emit('ok');
                    that.isShow=true
                    getAction("/temporary/diyTemporaryApplicantInfo/updateIsdisabledByuserid").then((res) => {});
                  } else {
                    that.$message.warning(res.message);
                  }
                }).finally(() => {
                  that.close();
                })
              } else {
                this.$message.error("请勿选择大类！")
              }
            }
          });
        },
      ExportPDF(){
         let that =this;
          postAction(this.exportPdfUrl,this.professorInfo).then((res)=>{
            let url = this.downloadPdfUrl+res.message
            console.log(url)
            if(this.isIosW){
              console.log("进入")
              that.geturl.url = window._CONFIG['domianURL']+url
              that.geturl.show =true
              console.log(that.geturl.show)
            }else {
              let a = document.createElement('a') //创建a标签
              a.href = window._CONFIG['domianURL']+url
              a.click()
            }

          })
      },
      saveTemp(){
        let that =this;
        console.log("进入父组件保存");
                  console.log("表单提交数据",this.professorInfo);
                  let method = '';
                  method = 'post';
                  httpAction("/temporary/diyTemporaryApplicantInfo/SaveTemp",this.professorInfo,method).then((res)=>{
                    console.log("res:"+res);
                    if(res.success){
                      console.log("res:"+res);
                      that.$message.success(res.message);
                      that.$emit('ok');
                    }else{
                      that.$message.warning("保存失败");
                    }
                  })
                },
      setfiled(data){
        this.professorInfo.professorName=data.professorName;
        this.professorInfo.professorSex=data.professorSex;
        this.professorInfo.professorBirthday=data.professorBirthday;
        this.professorInfo.professorIdentity=data.professorIdentity;
        this.professorInfo.professorEducationBackground=data.professorEducationBackground;
        this.professorInfo.professorDegree=data.professorDegree;
        this.professorInfo.professorAddress=data.professorAddress;
        this.professorInfo.professorHomeAddress=data.professorHomeAddress;
        this.professorInfo.professorHealth=data.professorHealth;
        this.professorInfo.professorOfficeTel=data.professorOfficeTel;
        this.professorInfo.professorPhone=data.professorPhone;
      },
      setfiled1(data){
        this.professorInfo.professorMajor=data.professorMajor;
        this.professorInfo.professorSchool=data.professorSchool;
        this.professorInfo.professorGraduateDate=data.professorGraduateDate;
        this.professorInfo.professorDeclareCategory=data.professorDeclareCategory;
        this.professorInfo.professorWorkMajor=data.professorWorkMajor;
        this.professorInfo.professorMajorDate=data.professorMajorDate;
        this.professorInfo.professorBeginWork=data.professorBeginWork;
        this.professorInfo.professorWorkUnit=data.professorWorkUnit;
        this.professorInfo.professorPosition=data.professorPosition;
        this.professorInfo.professorTitle=data.professorTitle;
        this.professorInfo.professorProjectIntroduce=data.professorProjectIntroduce;
      },
      setfiled2(data){
        this.professorInfo.professorPhotoString=data.professorPhotoString;
        this.professorInfo.professorInfoPhotoString=data.professorInfoPhotoString;
        this.professorInfo.professorIdString=data.professorIdString;
        this.professorInfo.professorCommitmentString=data.professorCommitmentString;
        this.professorInfo.professorResumeString=data.professorResumeString;
        this.professorInfo.professorDegreeImageString=data.professorDegreeImageString;
        this.professorInfo.professorQualificationString=data.professorQualificationString;
        this.professorInfo.professorOtherString=data.professorOtherString;
        },
      select(){
        getAction("/temporary/diyTemporaryApplicantInfo/selectByuserid").then((res) => {
          console.log("123");
          console.log(res);
            this.professorInfo.professorName=res.result.professorName,
              this.professorInfo.professorSex=res.result.professorSex,
            this.professorInfo.professorSchool=res.result.professorSchool,
            this.professorInfo.professorBirthday=res.result.professorBirthday,
            this.professorInfo.professorPhotoString=res.result.professorPhotoString,
            this.professorInfo.professorMajor=res.result.professorMajor,
            this.professorInfo.professorGraduateDate=res.result.professorGraduateDate,
            this.professorInfo.professorEducationBackground=res.result.professorEducationBackground,
            this.professorInfo.professorDegree=res.result.professorDegree,
            this.professorInfo.professorWorkUnit=res.result.professorWorkUnit,
            this.professorInfo.professorAddress=res.result.professorAddress,
            this.professorInfo.professorDeclareCategory=res.result.professorDeclareCategory,
            this.professorInfo.professorPosition=res.result.professorPosition,
            this.professorInfo.professorBeginWork=res.result.professorBeginWork,
            this.professorInfo.professorTitle=res.result.professorTitle,
            this.professorInfo.professorWorkMajor=res.result.professorWorkMajor,
            this.professorInfo.professorMajorDate=res.result.professorMajorDate,
            this.professorInfo.professorIdentity=res.result.professorIdentity,
            this.professorInfo.professorHomeAddress=res.result.professorHomeAddress,
            this.professorInfo.professorHealth=res.result.professorHealth,
            this.professorInfo.professorOfficeTel=res.result.professorOfficeTel,
            this.professorInfo.professorPhone=res.result.professorPhone,
            this.professorInfo.professorProjectIntroduce=res.result.professorProjectIntroduce,
            this.professorInfo.professorLeadMsg=res.result.professorLeadMsg,
            this.professorInfo.professorApproveMsg=res.result.professorApproveMsg,
            this.professorInfo.professorInfoPhotoString=res.result.professorInfoPhotoString,
            this.professorInfo.professorIdString=res.result.professorIdString,
            this.professorInfo.professorCommitmentString=res.result.professorCommitmentString,
            this.professorInfo.professorResumeString=res.result.professorResumeString,
            this.professorInfo.professorDegreeImageString=res.result.professorDegreeImageString,
            this.professorInfo.professorQualificationString=res.result.professorQualificationString,
            this.professorInfo.professorOtherString=res.result.professorOtherString
        });
      },
      // handler
      nextStep () {
        if (this.currentTab < 3) {
          this.currentTab += 1
        }
      },
      prevStep () {
        if (this.currentTab > 0) {
          this.currentTab -= 1
        }
      },
    }
  }
</script>

<style lang="less" scoped>
  .steps {
    max-width: 750px;
    margin: 16px auto;
  }
</style>